package com.qianchang.microfinance.view.credit.data;


import android.content.Context;
import android.text.TextUtils;

import com.qianchang.microfinance.R;
import com.qianchang.microfinance.bean.ContractBean;
import com.dm.library.adapter.CommonAdapter;
import com.dm.library.adapter.CommonViewHolder;

import java.util.List;

/**
 * 版 权: 深圳市迪蒙网络科技有限公司
 * 描 述:
 * 修 改 人: zhoulai
 * 修改时间: 2017/7/6 15:24
 */


public class ContractAdapter extends CommonAdapter<ContractBean> {


    private OnContractDeleteListener onContractDeleteListener;


    public ContractAdapter(Context mContext, List<ContractBean> beanList) {
        super(mContext, beanList, R.layout.adapter_contract);
    }

    @Override
    protected void convert(CommonViewHolder holder, final ContractBean contractBean, final int position) {
        String relationship = contractBean.getcontactRelationship();
        String title;
        holder.setBackgroundRes(R.id.tv_contract_icon,R.drawable.shape_circle_color_main);
        switch (relationship) {
            case "0":
                title = mContext.getString(R.string.label_father);
                break;
            case "1":
                title = mContext.getString(R.string.label_mother);
                break;
            case "2":
                title = mContext.getString(R.string.label_spouse);
                break;
            default:
                title = "";
                holder.setBackgroundRes(R.id.tv_contract_icon,R.drawable.img_mrtb);
                break;
        }
        holder.setText(R.id.tv_name, TextUtils.isEmpty(contractBean.getcontactPeopleName()) ? mContext.getString(R.string.name) : contractBean.getcontactPeopleName());
        holder.setText(R.id.tv_contract_icon, title);
        holder.setText(R.id.tv_phone_number, TextUtils.isEmpty(contractBean.getcontactPeoplePhone()) ? mContext.getString(R.string.phoneNumber) : contractBean.getcontactPeoplePhone());

    }

    public void setOnContractDeleteListener(OnContractDeleteListener onContractDeleteListener) {
        this.onContractDeleteListener = onContractDeleteListener;
    }

    public interface OnContractDeleteListener {
        void onDelete();
    }

    public void notifyDelete() {
        if (null != onContractDeleteListener) {
            onContractDeleteListener.onDelete();
        }
    }

}
